#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    timer = new QTimer;  //初始化一个对象
    picID=2;

    QImage img;
    img.load("E:\\QT_project\\temp\\objectTimer\\picture\\1.png");
    ui->label->setPixmap(QPixmap::fromImage(img));

    //定时器时间到，发出timerout信号
    connect(timer,&QTimer::timeout,this,&Widget::timeoutSlot);
}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_startButton_clicked()
{
    timer->start(TIMOUT);
}

void Widget::timeoutSlot()
{
    QString path("E:\\QT_project\\temp\\objectTimer\\picture\\");
    path += QString::number(picID);
    path += ".png";

    QImage img;
    img.load(path);
    ui->label->setPixmap(QPixmap::fromImage(img));

    picID++;
    if(5 == picID)
        picID = 1;
}

void Widget::on_stopButton_clicked()
{
    timer->stop();
}


void Widget::on_singleButton_clicked()
{
    QTimer::singleShot(100,this,SLOT(timeoutSlot()));
}

